package com.xiangban.controller;

import com.xiangban.aop.Permission;
import com.xiangban.model.*;
import com.xiangban.model.dto.OrderDto;
import com.xiangban.model.res.ApiResult;
import com.xiangban.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @Author ly
 * @date 2021/11/30 16:54
 */
@RestController
@RequestMapping("api/order")
@Api("订单控制器")
public class OderController {
    @Autowired
    private OrderService orderService;
    @ApiOperation("首页最新订单信息")
    @PostMapping("/home_order_info")
    @Permission
    public ApiResult<Object> homeOrderInfo(){
        return ApiResult.newSuccess(orderService.getOrderInfo());
    }

    @ApiOperation("选择服务对象列表")
    @PostMapping("/get_service_object")
    @Permission
    public ApiResult<Object> getServiceObject(){

        return ApiResult.newSuccess(orderService.getServiceObject());
    }
    @ApiOperation("添加服务对象")
    @PostMapping("/add_service_object")
    @Permission
    public ApiResult<Object> addServiceObject(@RequestBody  Relation relation) throws Exception {//姓名 性别  手机号 身份证 关系管理
        return ApiResult.newSuccess(orderService.addServiceObject(relation));
    }
    @ApiOperation("选择医院列表")
    @PostMapping("/get_hospital_list")
    public ApiResult<Object> getHospitalList(@RequestBody Hospital hospital){//经纬度

        return ApiResult.newSuccess(orderService.getHospitalList(hospital));
    }
    @ApiOperation("选择陪诊人")
    @PostMapping("/choose_employee")
    @Permission
    public ApiResult<Object> chooseEmployee(@RequestBody  UserAccompany userAccompany){//性别
        return ApiResult.newSuccess(orderService.chooseEmployee(userAccompany));
    }

    @ApiOperation("创建订单")
    @PostMapping("/submit_order")
    @Permission
    public ApiResult<Object> submitOrder(@RequestBody OrderDto orderDto) throws ParseException {
        return ApiResult.newSuccess(orderService.submitOrder(orderDto));
    }
    @ApiOperation("订单列表")
    @PostMapping("/List_order")
    @Permission
    public ApiResult<Object> ListOrder(@RequestBody  Order order){//status
        return ApiResult.newSuccess(orderService.ListOrder(order));
    }

    @ApiOperation("订单详情")
    @PostMapping("/order_particulars")
    @Permission
    public ApiResult<Object> orderParticulars(@RequestBody OrderDto order){//订单编号
        return ApiResult.newSuccess(orderService.orderParticulars(order));
    }

    @ApiOperation("订单取消")
    @PostMapping("/order_cancel")
    @Permission
    public ApiResult<Object> orderCancel(@RequestBody OrderDto order){
        return ApiResult.newSuccess(orderService.orderCancel(order));
    }
    @ApiOperation("订单评价")
    @PostMapping("/order_evaluate")
    @Permission
    public ApiResult<Object> orderEvaluate(@RequestBody OrderComment orderComment){
        return ApiResult.newSuccess(orderService.orderEvaluate(orderComment));
    }

    @ApiOperation("订单退款规则")
    @PostMapping("rule_rule")
    @Permission
    public ApiResult<Object> ruleRule(@RequestBody Order order) throws ParseException {//订单号

        return ApiResult.newSuccess(orderService.ruleRule(order));
    }
    @ApiOperation("退款订单生成")
    @PostMapping("refund_add")
    public ApiResult<Object> refudAdd(@RequestBody OrderRefund orderRefund) throws ParseException {
        return ApiResult.newSuccess(orderService.refudAdd(orderRefund));
    }
    @ApiOperation("申请退款")
    @PostMapping("/refund_order_list")
    public ApiResult<Object> refundOrderList(@RequestBody OrderRefund orderRefund) throws Exception {
        return ApiResult.newSuccess(orderService.refundOrderList(orderRefund));
    }
    /**
     * 暂未用
     * */
    @ApiOperation("确认下单")
    @PostMapping("/order_ok")
    @Permission
    public ApiResult<Object> orderOk(@RequestBody OrderDto orderDto){
        return ApiResult.newSuccess(orderService.orderOk(orderDto));
    }
    @ApiOperation("退款列表")
    @PostMapping("/refund_list")
    @Permission
    public ApiResult<Object> refundList(){

        return ApiResult.newSuccess(orderService.refundList());
    }
    @ApiOperation("退款详情")
    @PostMapping("refund_details")
    @Permission
    public ApiResult<Object> refundDetails(@RequestBody OrderRefund orderRefund){

        return ApiResult.newSuccess(orderService.refundDetails(orderRefund));
    }
    @ApiOperation("解绑关系人")
    @PostMapping("/remove_binding")
    @Permission
    public void removeBinding(@RequestBody Relation relation){//
        orderService.removeBinding(relation);
   }
   @PostMapping("sss")
    public String sss(){
        return orderService.sss();
   }
}
